<?php
session_start();

$main_image;

# include("password.php");
$dirbase_simple = "/cf/";

define("ROOT_PATH", "/var/www/cf/");
define("INCL_PATH", "/includes/");
define("PHP_EXT", ".php");

$dirbase = "/var/www/cf/";
$web_server_data = "web_server_data/"; # relative to dirbase

$mypage = "";

# echo "IN INDEX.PHP"

# session_cache_limiter(2880);

if (isset($_GET["id"])) {
	$get_id = $_GET["id"];
	// print "GET is" . $_GET["id"]  . "<br />\n";
	$id = explode("/", $get_id);
} else {
	// $get_id = "";
	$id[0] = "";
	// $mypage = file_get_contents(ROOT_PATH . INCL_PATH . "intro" . PHP_EXT);
}

if($id[0] != "UpdateData.php" && $id[0] != "AddData.php" && $id[0] != "DeleteData.php") {


?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">

<head>

  <meta charset="utf-8">
  <title>Deep characterization of blood cell miRNomes</title>
  <link rel="stylesheet" href="docsupport/style.css">
  <link rel="stylesheet" href="docsupport/prism.css">
  <link rel="stylesheet" href="chosen.css">
  <style type="text/css" media="all">
    /* fix rtl for demo */
    .chosen-rtl .chosen-drop { left: -9000px; }
  </style>
<link rel="stylesheet" href="https://code.jquery.com/ui/1.10.4/themes/smoothness/jquery-ui.css" /> 
<!-- <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.6.4/jquery.min.js" type="text/javascript"></script> -->
<script src="https://code.jquery.com/jquery-1.11.1.min.js"></script>
<script src="chosen.jquery.js" type="text/javascript"></script>
<link rel="stylesheet" href="https://cdn.datatables.net/plug-ins/1.10.6/integration/jqueryui/dataTables.jqueryui.css" />
<script src="https://cdn.datatables.net/1.10.6/js/jquery.dataTables.min.js"></script>
<script src="csvToArray.v2.1.min.js" type="text/javascript"></script>
<!-- <script src="jquery.csv-0.71.min.js" type="text/javascript"></script> -->

                <style type="text/css" title="currentStyle">
                        @import "TableTools/media/css/demo_page.css";
                        @import "TableTools/media/css/demo_table.css";
                        @import "TableTools/css/TableTools.css";
                </style>
                <!-- <script type="text/javascript" charset="utf-8" src="TableTools/media/js/jquery.js"></script> -->
                <!-- <script type="text/javascript" charset="utf-8" src="TableTools/media/js/jquery.dataTables.js"></script> -->
                <script type="text/javascript" charset="utf-8" src="TableTools/media/ZeroClipboard/ZeroClipboard.js"></script>
                <script type="text/javascript" charset="utf-8" src="TableTools/media/js/dataTables.tableTools.js"></script>
                <script type="text/javascript" charset="utf-8">
                </script>


<!-- <script src="<?php echo $dirbase_simple ?>jquery/DataTables-1.10.4/media/js/jquery.dataTables.js"></script> -->

<script>

// a simple check to *try* and ensure valid URIs are used:
function protocolCheck(link) {
    var proto = ['http:', 'https:'];

    for (var i = 0, len = proto.length; i < len; i++) {
        // if the link begins with a valid protocol, return the link
        if (link.indexOf(proto[i]) === 0) {
            return link;
        }
    }

    // otherwise assume it doesn't, prepend a valid protocol, and return that:
    return document.location.protocol + '//' + link;
}

function createImage(imgURL,pageURL,divlabel) {
    // stop the default event from happening:
    // e.preventDefault();
    // var parent = this.parentNode;
	
    var div = document.getElementById(divlabel);	

    /* var headerdiv = document.getElementById(divlabel); 
    headera = document.createElement('a');
    headera.text = "TEST";
    headera.href = pageURL;
    headera.target = "_blank";
    headerdiv.appendChild(headera); */

    divlabelhide = "#" + divlabel + " img"; 
	
    $(divlabelhide).hide();	     
	
    /* checking the protocol (calling the previous function),
       of the URIs provided in the text input elements: */
    // src = protocolCheck(document.getElementById('imgURL').value);
    // href = protocolCheck(document.getElementById('pageURL').value);
	
    src = imgURL;
    href = pageURL;	

    // creating an 'img' element, and an 'a' element
    var img = document.createElement('img'),
        a = document.createElement('a');

    // parentElement = img.parentElement;  	

    // setting the src attribute to the (hopefully) valid URI from above
    img.src = src;

    // setting the href attribute to the (hopefully) valid URI from above
    a.href = href;
    a.target = "_blank";
    // appending the 'img' to the 'a'
    a.appendChild(img);
    // inserting the 'a' element *after* the 'form' element
    // parent.parentNode.insertBefore(a, parent.nextSibling);
    // parent.insertBefore(a, parent.nextSibling);
    div.appendChild(a);	
}

function makeTable(array2,id) {
    var table = document.createElement('table');
    table.id = id;

    var head = document.createElement('thead');
    var row = document.createElement('tr');

    for (var j = 0; j < 12; j++) {  // array2[i].length; j++) {
	    var cell = document.createElement('th');
	    cell.textContent = array2[0][j];
	    row.appendChild(cell);
    }

    head.appendChild(row);
    table.appendChild(head);

    var foot = document.createElement('tfoot'); 
    var row = document.createElement('tr');

     for (var j = 0; j < 12; j++) {  // array2[i].length; j++) {
             var cell = document.createElement('th');
             // cell.textContent = array2[0][j] + "test";
            row.appendChild(cell);
    }	    
    foot.appendChild(row);
    table.appendChild(foot);

    var body = document.createElement('tbody');

    for (var i = 1; i < array2.length; i++) {
        var row = document.createElement('tr');
        for (var j = 0; j < 12; j++) {  // array2[i].length; j++) {
            var cell = document.createElement('td');
            cell.textContent = array2[i][j];
            row.appendChild(cell);
        }
        body.appendChild(row);
    }

    table.appendChild(body);
	
    // document.body.appendChild(table);

    return table;
}


function createTable(tableData,id) {
  var table = document.createElement('table')
    , tableBody = document.createElement('tbody');

    table.id = id;
    
  tableData.forEach(function(rowData) {
    var row = document.createElement('tr');

    rowData.forEach(function(cellData) {
      var cell = document.createElement('td');
      cell.appendChild(document.createTextNode(cellData));
      row.appendChild(cell);
    });

    tableBody.appendChild(row);
  });

  table.appendChild(tableBody);
  document.body.appendChild(table);
  
  return table;
}

function getPrecision(scinum) {
  var arr = new Array();
  // Get the exponent after 'e', make it absolute.  
  arr = scinum.split('e');
  var exponent = Math.abs(arr[1]);

  // Add to it the number of digits between the '.' and the 'e'
  // to give our required precision.
  var precision = new Number(exponent);
  arr = arr[0].split('.');
  precision += arr[1].length;

  return precision;
}

function match(s) { 
        // console.log("in match " + s);
        
        if (s.match(/^[-+]?[1-9]\.[0-9]+e[-]?[0-9][0-9]*$/)) {
        // if (s.match(/[+\-]?(?:0|[1-9]\d*)(?:\.\d*)?(?:[eE][+\-]?\d+)?/)) {
        // console.log("in match 2");
        s = (+s).toFixed(getPrecision(s));
        // alert("Matched " + s);
	}

	return (s);

}

function toggle(toggle_button,toggle_element,page) {
        var ele = document.getElementById(toggle_element);
        var text = document.getElementById(toggle_button);
        if(ele.style.display == "block") {
                ele.style.display = "none";
                text.innerHTML = "Show details";
                text.value="Show details";
        }
	else {
		$("#" + toggle_element).load(page);
                ele.style.display = "block";
                text.innerHTML = "Hide details";
                text.value="Hide details";
        }
}
</script>
<script src="https://code.jquery.com/jquery-1.11.1.min.js"></script> 
<!--  <script src="dynatable/jquery.dynatable.js" type="text/javascript"></script> -->
<link rel="stylesheet" href="https://cdn.datatables.net/plug-ins/1.10.6/integration/jqueryui/dataTables.jqueryui.css" />
<script src="https://cdn.datatables.net/1.10.6/js/jquery.dataTables.min.js"></script>

<script>
jQuery.fn.dataTableExt.oSort['allnumeric-asc']  = function(a,b) {
          console.log("in allnumeric-asc");
          x = match(a); 
          // var x = parseFloat(x);
          
          y = match(b);
          // var y = parseFloat(y);
          return ((x < y) ? -1 : ((x > y) ?  1 : 0));
        };
 
jQuery.fn.dataTableExt.oSort['allnumeric-desc']  = function(a,b) {
          // console.log("in allnumeric-desc");
          x = match(a); 
	  // console.log("x is " + x);
          // var x = parseFloat(x);
	  y = match(b);
	  // console.log("y is " + y);
          // var y = parseFloat(y);
          return ((x < y) ? 1 : ((x > y) ?  -1 : 0));
        };
</script>

<script src="<?php echo $dirbase_simple ?>jquery/media/js/numeric-comma.js"></script>
                <script type="text/javascript" charset="utf-8" src="TableTools/media/js/dataTables.tableTools.js"></script>
<!-- <script src="jquery.dataTables.js"></script> -->
  <script src="chosen.jquery.js" type="text/javascript"></script>
  <script src="docsupport/prism.js" type="text/javascript" charset="utf-8"></script>
  <script type="text/javascript">
	var config = {
//	{ search_contains: true },
      '.chosen-select'           : { },
      '.chosen-select-deselect'  : {allow_single_deselect:true},
      '.chosen-select-no-single' : {disable_search_threshold:10},
      '.chosen-select-no-results': {no_results_text:'Oops, nothing found!'},
      '.chosen-select-width'     : {width:"95%"}
    }
    for (var selector in config) {
      $(selector).chosen(config[selector]);
    }

  </script>



</script>
<style>
body { background-color: white; }
</style>

</head>

<body>

<?php

	switch ($id[0]) {
	case 'about.php':
		$main_image = "dnanumbers_wider1.png";
		break;
	case 'intro.php':
		$main_image = "dnanumbers_wider2.png";
		break;
	case 'intro2.php':
		$main_image = "dnanumbers_wider3.png";
		break;
	default:
		                $main_image = "dnanumbers_wider1.png";
				                break;
	}

?>

<div class="block4" id="header">
<img class="aligncenter" src="/cf/pics/dnanumbers_wider_all.png" alt="ccb_cf" usemap="#ccb_cf" width="750" height="303" />
<map name="ccb_cf">
<area coords="601,21,691,46" shape="rect" href="/cf/?id=about.php" />
<area coords="563,71,733,93" shape="rect" href="/cf/?id=intro.php" />
<area coords="571,119,726,144" shape="rect" href="/cf/?id=intro2.php" />
<!-- <area coords="577,169,713,195" shape="rect" href="/cf/about.php" />
<area coords="588,217,703,245" shape="rect" href="/cf/about.php" /> -->
<area coords="347,0,525,63" shape="rect" href="https://www.ccb.uni-saarland.de" target="_blank" />
<area coords="347,90,525,136" shape="rect" href="http://www.uni-saarland.de/en/home.html" target="_blank" />
<area coords="347,151,546,210" shape="rect" href="http://www.zbi.uni-saarland.de/en" target="_blank" />
<area coords="347,223,545,297" shape="rect" href="http://www.uniklinikum-saarland.de/einrichtungen/fachrichtungen/biophysik/biophysik1/" target="_blank" />
</map>
</div>
<?php

}


switch ($id[0]) {
case 'intro.php':
	$main_image = "cf2.png";
	include(ROOT_PATH . INCL_PATH . "intro" . PHP_EXT);
        break;
case 'intro2.php':
	$main_image = "cf3.png";
	include(ROOT_PATH . INCL_PATH . "intro2" . PHP_EXT);
        break;
case 'intro2_outside.php':
	include(ROOT_PATH . INCL_PATH . "intro2_outside" . PHP_EXT);
        break;
case 'intro3.php':
	include(ROOT_PATH . INCL_PATH . "intro3" . PHP_EXT);
        break;
case 'intro4.php':
	include(ROOT_PATH . INCL_PATH . "intro3" . PHP_EXT);
        break;
case 'progress.php':
	include(ROOT_PATH . INCL_PATH . "progress" . PHP_EXT);
        break;
case 'progress_outside.php':
	include(ROOT_PATH . INCL_PATH . "progress_outside" . PHP_EXT);
        break;
case 'UpdateData.php':
	include(ROOT_PATH . INCL_PATH . "UpdateData" . PHP_EXT);
        break;
case 'AddData.php':
	include(ROOT_PATH . INCL_PATH . "AddData" . PHP_EXT);
        break;
case 'DeleteData.php':
	include(ROOT_PATH . INCL_PATH . "DeleteData" . PHP_EXT);
        break;
case 'prepare.php':
	include(ROOT_PATH . INCL_PATH . "prepare" . PHP_EXT);
	break;
case 'prepare_outside.php':
	include(ROOT_PATH . INCL_PATH . "prepare_outside" . PHP_EXT);
	break;
case 'pub_citations-each.php':
	include(ROOT_PATH . INCL_PATH . "pub_citations-each" . PHP_EXT);
	break;
case 'pass.php':
	include(ROOT_PATH . INCL_PATH . "pass" . PHP_EXT);
	break;
case 'pass2.php':
	include(ROOT_PATH . INCL_PATH . "pass2" . PHP_EXT);
	break;
case 'plot_publications.php':
	include(ROOT_PATH . INCL_PATH . "plot_publications" . PHP_EXT);
	break;
case 'generate_newspage.php':
	include(ROOT_PATH . INCL_PATH . "generate_newspage" . PHP_EXT);
	break;
case 'generate_pubs.php':
	include(ROOT_PATH . INCL_PATH . "generate_pubs" . PHP_EXT);
	break;
case 'search_term_pubmed.php':
	include(ROOT_PATH . INCL_PATH . "search_term_pubmed" . PHP_EXT);
	break;
case 'about.php':
	$main_image = "cf1.png";
	include(ROOT_PATH . INCL_PATH . "about" . PHP_EXT);
	break;
default:
	include(ROOT_PATH . INCL_PATH . "about" . PHP_EXT);
	break;
}
?>
<?php
if($id[0] != "UpdateData.php" && $id[0] != "AddData.php" && $id[0] != "DeleteData.php") {
?>

  <!-- <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.6.4/jquery.min.js" type="text/javascript"></script> -->


<style>
body { background-color: white; }
</style>
<footer>
<span><a class="btn btn-link" href="https://www.uni-saarland.de/en/footer/dialogue/legal-notice.html" target="_blank" aria-label="link Imprint">Imprint</a></span>
<span><a class="btn btn-link" href="https://www.uni-saarland.de/en/footer/dialogue/privacy.html" target="_blank" aria-label="link Data protection">Data protection</a></span>
</footer>
<?php	
echo '</body>';
echo '</html>';
}

